// 切换菜单的样式

function switchTab(){       //切换选项卡
    console.log("已执行");

    let nav=document.querySelector(".main-nav");        //获取导航栏

    let tab=nav.getElementsByTagName("a");      //获取切换的列表

    for(let i=0;i<tab.length;i++){
        tab[i].onclick=function(){
            for(let j=0;j<tab.length;j++){      //清除所有的active
                tab[j].classList.remove("active");
            }
            tab[i].classList.add("active");     //给当前点击的选项添加active
        }
    }
}

switchTab();

let curScrollHeight=500;

window.onscroll=function(){

    let nav=document.querySelector(".main-nav");

    let scrollHeight = document.documentElement.scrollTop | document.body.scrollTop;  //获取滚动条的高度

    if(scrollHeight<500){
        nav.style.position="static";
    }

    if(scrollHeight>=500){
        if(scrollHeight<curScrollHeight){
            nav.style.position="fixed";
            nav.style.left="0";
            nav.style.top="0";
            curScrollHeight=scrollHeight;
            console.log(curScrollHeight);
        }else{
            nav.style.position="static";
            curScrollHeight=scrollHeight;
        }
       
    }
}